package mipo.top.base.controller;

import mipo.top.base.Dto.EmailDto;
import mipo.top.base.Dto.RegisterDto;
import mipo.top.base.Dto.WechatDto;
import mipo.top.base.service.IRegisterService;
import mipo.top.base.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("/register")
public class RegisterCotroller {

    @Autowired
    private IRegisterService registerService;

    @PostMapping("/phone")
    public JsonResult phones(@RequestBody RegisterDto dto){
        try{
            registerService.registerPhone(dto);
            return JsonResult.me();
        }catch (Exception e){
            e.printStackTrace();
            return JsonResult.me().setMsg(e.getMessage());
        }
    } @PostMapping("/wechat/binder")
    public JsonResult binder(@RequestBody WechatDto dto){
        try{
            HashMap<String, Object> map = registerService.binderPhone(dto);
            return JsonResult.me().setResultData(map);
        }catch (Exception e){
            e.printStackTrace();
            return JsonResult.me().setMsg(e.getMessage());
        }
    }
    @PostMapping("/email")
    public JsonResult email(@RequestBody EmailDto dto){
        try{
            registerService.registerEmail(dto);
            return JsonResult.me();
        }catch (Exception e){
            e.printStackTrace();
            return JsonResult.me().setMsg(e.getMessage());
        }
    }
}
